<?php
class User {
	
	const ACCESS_ROOT = 'root';
	
	const ACCESS_TRANSLATOR = 'translator';
	
	const ACCESS_USER = 'user';
	
	public $id;
	
	public $login;
	
	public $password;
	
	public $access;
	
	public $lastLogin;
	
	public $regDate;
	
	protected $_model;
	
	public function __construct($userId = null) {
		$this->_model = new UserObjModel();
		if($userId) {
			$userData = $this->_model->getUserById($userId);
			foreach ($userData as $data) {
				$this->id = $data->id;
				$this->login = $data->login;
				$this->password = $data->password;
				$this->access = $data->access;
				$this->regDate = $data->date_created;
				$this->lastLogin = $data->date_last_login;
			}
		}
	}
	
	public function __get($name) {
		if(isset($name)) {
			return $this->$name;
		}
	}
	
	public function isRoot() {
		return ($this->access == self::ACCESS_ROOT);
	}
	
	public function isTranslator() {
		 return ($this->access == self::ACCESS_TRANSLATOR);
	}
	
	public function setLastLogin() {
		$this->_model->setLastLogin($this->id);
	}

	public function getCommonAccessWebsites() {
		return $this->_model->getCommonAccessWebsites($this->id);
	}
}